package com.cn.hnust.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cn.hnust.dao.UserMapper;
import com.cn.hnust.pojo.User;
import com.cn.hnust.service.IUserService;
import com.cn.hnust.util.Page;

@Service("userService")
public class UserServiceImpl implements IUserService {

	@Autowired
	private UserMapper userDao;

	
	public User getUserById(Integer userId) throws Exception {
		// TODO Auto-generated method stub
		if (userId <= 0) {
			return null;
		}
		return this.userDao.selectByPrimaryKey(userId);
	}

	
	public List<User> getUsers() {
		List<User> u = userDao.getUsers();
		System.out.println(u.get(0).getCreatetime());
		return userDao.getUsers();

	}

	public User getUser(String users) {
		// TODO Auto-generated method stub

		return this.userDao.getUser(users);
	}

	public int insert(User user) {

		if (user != null) {
			return userDao.insert(user);

		} else {
			return 0;

		}

	}

	
	public int delUser(int id) {
		// TODO Auto-generated method stub
		int a = userDao.deleteByPrimaryKey(id);
		if (a > 0) {
			return userDao.deleteByPrimaryKey(id);
		} else {

			return 0;
		}

	}

	
	public List<User> selectPersons(String userName,Page page) {
		// TODO Auto-generated method stub
		List<User> user = userDao.selectPersons(userName,page);
		if (user != null) {
			return userDao.selectPersons(userName,page);
		} else {

			return null;
		}

	}

	
	public List<User> queryAllRecord(Page page) {
		// TODO Auto-generated method stub
		
		
		return userDao.queryAllRecord(page);
	}

	
	public int getCount() {
		// TODO Auto-generated method stub
		
		return userDao.getCount();
	}

	
	public int updateByPrimaryKey(User user) {
		// TODO Auto-generated method stub
		int a=userDao.updateByPrimaryKey(user);
		if(a > 0){
		return userDao.updateByPrimaryKey(user);		
	}
		return 0;
		

}

	
	public int getCountmh(String userName) {
		// TODO Auto-generated method stub
		userDao.getCountmh(userName);
		return userDao.getCountmh(userName);
	}
	}